//
//  DetailGuideViewController.m
//  ITASTRA
//
//  Created by Apple on 06/12/12.
//  Copyright (c) 2012 me. All rights reserved.
//

#import "DetailGuideViewController.h"

@interface DetailGuideViewController ()

@end

@implementation DetailGuideViewController
@synthesize mainid,catId;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


-(void)getdata
{
    [MBProgressHUD  hideHUDForView:self.navigationController.view
                          animated:YES];
    
    
    NSLog(@"~~~~~~%@",[XMLReader  dictionaryForXMLString:modal.stringRx
                                                   error:nil]);
    NSDictionary *dict = [XMLReader  dictionaryForXMLString:modal.stringRx
                                                      error:nil];
    arrayDetail = [[NSMutableArray alloc] init];
    
    if([dict objectForKey:@"objects"])
    {
        if([[dict objectForKey:@"objects"] objectForKey:@"object"])
        {
            if([[[dict objectForKey:@"objects"] objectForKey:@"object"] isKindOfClass:[NSArray  class]])
            {
                arrayDetail =[[NSMutableArray  alloc] initWithArray:[[dict objectForKey:@"objects"] objectForKey:@"object"]];
            }
            else
                [arrayDetail  addObject:[[dict objectForKey:@"objects"] objectForKey:@"object"]];
        }
    }
    
    NSLog(@"%@",arrayDetail);
    
    if([arrayDetail  count]>0)
    {
        imageDetails.imageURL = [NSURL  URLWithString:[[arrayDetail objectAtIndex:0] objectForKey:@"first_image_big"]];
        [webDetail loadHTMLString:[[arrayDetail objectAtIndex:0] objectForKey:@"description"] baseURL:nil];
        lbAddress.text = [NSString stringWithFormat:@"%@ %@,%@ %@ %@",[[arrayDetail objectAtIndex:0] objectForKey:@"address_street_number"],[[arrayDetail objectAtIndex:0] objectForKey:@"address_street"],[[arrayDetail objectAtIndex:0] objectForKey:@"address_region"],[[arrayDetail objectAtIndex:0] objectForKey:@"address_province"],[[arrayDetail objectAtIndex:0] objectForKey:@"address_zip"]];
    }
    
    
    [tblView  reloadData];
}
-(void)getError
{
    [MBProgressHUD  hideHUDForView:self.navigationController.view
                          animated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [arrayDetail count];
}

// Customize the appearance of table view cells.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"cellGuide";
    
    GuideCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[GuideCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
    }
    
//    NSString *old_Stra_Photo = theList.image;
    NSString *path = [[[arrayDetail objectAtIndex:indexPath.row] objectForKey:@"first_image_big"] stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
    NSURL *url = [NSURL URLWithString:path];
    //    NSData *data = [NSData dataWithContentsOfURL:url];
    //    UIImage *imgTemp = [[UIImage alloc] initWithData:data];
    
    
    
//    theList = [app.listArray objectAtIndex:indexPath.row];
    cell.imgDisplay_G.imageURL = url;
    
    cell.titleDisplay_G.text = [[arrayDetail objectAtIndex:indexPath.row] objectForKey:@"name"];
    cell.descriptionDisplay_G.text = [[arrayDetail objectAtIndex:indexPath.row] objectForKey:@"category"];
    cell.count_straordinariDisplay_G.text = [[arrayDetail objectAtIndex:indexPath.row] objectForKey:@"info1"];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    ShopDetailViewController *detailView = [self.storyboard instantiateViewControllerWithIdentifier:@"SHOPID"];
    detailView.dictShop = [arrayDetail  objectAtIndex:indexPath.row];
//    detailView.mainid = [NSString stringWithFormat:@"%d",theList.objID];
//    detailView.catId  = [[arrayDetail  objectAtIndex:indexPath.row] objectForKey:@"id"];
    
    //    theList = [app.listArray objectAtIndex:indexPath.row];
    
    //    detailView.theList = theList;
    [self.navigationController pushViewController:detailView animated:YES];
    
    
}

//detailGuid
- (void)viewDidLoad
{
    NSLog(@"%s",__PRETTY_FUNCTION__);
    MBProgressHUD *hud = [MBProgressHUD  showHUDAddedTo:self.navigationController.view
                                               animated:YES];
    hud.labelText = @"Fetching";
    
    modal = [[ModalController  alloc] init];
    modal.delegate = self;
    [modal sendTheRequestWithPostString:nil withURLString:[NSString stringWithFormat:@"http://www.italiastraordinaria.it/api/guide/%@/%@.xml",self.mainid,self.catId]];
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
